﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：CardModifyInfo
// 文件功能描述：人员改卡
//
// 
// 创建标识：2012-02-16 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    public class CardModifyInfo
    {
        /// <summary>
        /// 人员ID
        /// </summary>
        public int PID
        {
            get;
            set;
        }
        /// <summary>
        /// 人员编号
        /// </summary>
        public string EmpNo
        {
            get;
            set;
        }
        /// <summary>
        /// 部门名称
        /// </summary>
        public string deptName
        {
            get;
            set;
        }
        /// <summary>
        /// 人员类型
        /// </summary>
        public string PersonTypeName
        {
            get;
            set;
        }
        /// <summary>
        /// 人员姓名
        /// </summary>
        public string PName
        {
            get;
            set;
        }
        /// <summary>
        /// 部门编号
        /// </summary>
        public int Dep_ID
        {
            get;
            set;
        }
        /// <summary>
        /// 卡序列号
        /// </summary>
        public Int64 CardSerial
        {
            get;
            set;
        }
        /// <summary>
        /// 押金
        /// </summary>
        public decimal CardOptDeposit
        {
            get;
            set;
        }
        /// <summary>
        /// 消费余额
        /// </summary>
        public decimal Balance
        {
            get;
            set;
        }
        /// <summary>
        /// 有效期始
        /// </summary>
        public DateTime InureTime
        {
            get;
            set;
        }
        /// <summary>
        /// 有效期止
        /// </summary>
        public DateTime ExpiredTime
        {
            get;
            set;
        }
        /// <summary>
        /// 操作员
        /// </summary>
        public string OperatorID
        {
            get;
            set;
        }
        /// <summary>
        /// 卡状态
        /// </summary>
        public string CardStatus
        {
            get;
            set;
        }
        /// <summary>
        /// 工作状态（即在职状态）
        /// </summary>
        public string WorkStatus
        {
            get;
            set;
        }
        public bool blSubsidyCard
        {
            get;
            set;
        }

        private DataAccessCardModify dar;
        private int CardModifycount;
        public int _CardModifycount
        {
            get { return CardModifycount; }
        }
        public CardModifyInfo(bool isgetcount)
        {
            dar = new DataAccessCardModify();
            if (isgetcount)
            {
                CardModifycount = GetCardModifyCount();
            }
        }
        public CardModifyInfo()
        { }

        /// <summary>
        /// 获取未发卡人员数量
        /// </summary>
        /// <returns></returns>
        private int GetCardModifyCount()
        {
            return dar.GetCardModifyCount();
        }

        /// <summary>
        /// 根据条件获取数量
        /// </summary>
        /// <returns></returns>
        public int GetCardModifyCountWhere(string query)
        {
            return dar.GetCardModifyCountWhere(query);
        }

        /// <summary>
        /// 获取未发卡人员信息（分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<CardModifyInfo> SelCardModifyInfo(int pagesize, int startindex, string strquery)
        {
            IList<CardModifyInfo> carlist = new List<CardModifyInfo>();
            CardModifyInfo carinfo;
            DataSet ds = dar.SelCardModifyInfo(pagesize, startindex, strquery);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                carinfo = new CardModifyInfo()
                {
                    PID = Convert.ToInt32(item["PID"]),
                    EmpNo = item["EmpNo"].ToString(),
                    deptName = item["deptName"].ToString(),
                    PersonTypeName = item["PERSONTYPENAME"].ToString(),
                    PName = item["PName"].ToString(),
                    CardSerial = Convert.ToInt64(item["CardSerial"]),
                    Balance = Convert.ToDecimal(item["Balance"])
                };
                carlist.Add(carinfo);
            }
            return carlist;
        }

        /// <summary>
        /// 获取部门列表（用于绑定下拉框）
        /// </summary>
        /// <returns></returns>
        public DataSet GetdeptName()
        {
            return dar.GetdeptName();
        }

        /// <summary>
        /// 根据编号获取一条人员信息
        /// </summary>
        /// <param name="supplierNo"></param>
        /// <returns></returns>
        public CardModifyInfo GetCardModifyInfoOne(string id)
        {
            dar = new DataAccessCardModify();
            DataSet ds = dar.GetCardModifyInfoOne(id);
            CardModifyInfo info = new CardModifyInfo();
            info.PID = int.Parse(ds.Tables[0].Rows[0]["PID"].ToString());
            info.EmpNo = ds.Tables[0].Rows[0]["EmpNo"].ToString();
            info.deptName = ds.Tables[0].Rows[0]["deptName"].ToString();
            info.PersonTypeName = "员工卡";
            info.PName = ds.Tables[0].Rows[0]["PName"].ToString();
            info.Dep_ID = int.Parse(ds.Tables[0].Rows[0]["Dep_ID"].ToString());
            info.CardSerial = Convert.ToInt64(ds.Tables[0].Rows[0]["CardSerial"].ToString());
            info.Balance = Convert.ToDecimal(ds.Tables[0].Rows[0]["Balance"]);
            info.CardStatus = ds.Tables[0].Rows[0]["CardStatus"].ToString();
            info.WorkStatus = ds.Tables[0].Rows[0]["WorkStatus"].ToString();
            info.ExpiredTime = Convert.ToDateTime(ds.Tables[0].Rows[0]["ExpiredTime"]);
            info.CardOptDeposit = Convert.ToDecimal(ds.Tables[0].Rows[0]["Condeposit"]);
            info.blSubsidyCard = Convert.ToBoolean(ds.Tables[0].Rows[0]["Entertaincard"]);
            return info;
        }

        /// <summary>
        /// 保存（给人员改卡）
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int SaveCard(CardModifyInfo car)
        {
            object[] objcar = new object[] { car.EmpNo, car.CardOptDeposit, car.ExpiredTime, car.OperatorID, car.blSubsidyCard };
            return dar.SaveCard(objcar);
        }
    }
}
